using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Services;
using Sudoku.Lang;

namespace Sudoku.Menu
{
	public class CreditsScene: ExtendedGameComponent
	{

		Texture2D bg;
		Rectangle bgPos;
		Color bgColor;

		SpriteFont headerFont;
		Color headerColor;
		String header;
		Vector2 headerPos;

		SpriteFont titleFont;
		String title1;
		Vector2 title1Pos;
		String title2;
		Vector2 title2Pos;
		String title3;
		Vector2 title3Pos;

		SpriteFont nameFont;
		String name1;
		Vector2 name1Pos;
		String name2;
		Vector2 name2Pos;
		String name3;
		Vector2 name3Pos;
		String name4;
		Vector2 name4Pos;

		string message;
		SpriteFont messageFont;
		Vector2 messagePos;

		IInputManager inputService;

		public CreditsScene(Game game)
			: base(game)
		{

		}

		public override void Initialize()
		{
			inputService = Game.Services.GetService(typeof(IInputManager)) as IInputManager;
			inputService.OnTap += new InputManager.TouchEvent(OnTap);
			inputService.OnBack += new InputManager.PhoneButtonEvent(Back);

			bg = textureService.Background("General");
			bgPos = new Rectangle(0, 0, 480, 800);
			bgColor = Color.White;

			//HEADER
			headerFont = fontService.Font(FontType.Delicious48);
			header = "CREDITS";
			headerColor = new Color(0, 102, 153);
			headerPos = new Vector2(240 - (headerFont.MeasureString(header).X * 0.5f), 20);

			titleFont = fontService.Font(FontType.Delicious26);
			title1 = LocalizedStrings.CreditsLn1;
			title1Pos = new Vector2(25, 120);
			title2 = LocalizedStrings.CreditsLn2;
			title2Pos = new Vector2(25, 250);
			title3 = LocalizedStrings.CreditsLn3;
			title3Pos = new Vector2(25, 350);

			nameFont = fontService.Font(FontType.DeliciousSmallCaps22);
			name1 = "Jacopo Musso";
			name1Pos = new Vector2(45, 160);
			name2 = "Filippo Fantini";
			name2Pos = new Vector2(45, 190);
			name3 = "Erica Segale";
			name3Pos = new Vector2(45, 290);
			name4 = "Giuseppe Maggiore";
			name4Pos = new Vector2(45, 390);

			//MESSAGE
			messageFont = fontService.Font(FontType.DeliciousSmallCaps22);
			message =  LocalizedStrings.EndMessageWin;
			messagePos = new Vector2(240 - (messageFont.MeasureString(message).X * 0.5f), 750);

			soundService.TurnPageSound();

			base.Initialize();
		}

		protected override void Dispose(bool disposing)
		{
			inputService.OnTap -= new InputManager.TouchEvent(OnTap);
			inputService.OnBack -= new InputManager.PhoneButtonEvent(Back);

			base.Dispose(disposing);
		}

		private void Back()
		{
			soundService.PlaySound(SoundType.Fumble);
			StateManagement.StateManager.StartMenu(Game);
		}

		private void OnTap(Vector2 pos)
		{
			StateManagement.StateManager.StartMenu(Game);
			soundService.TurnPageSound();
		}

		public override void Draw(GameTime gameTime)
		{

			spriteBatch.Begin();

			spriteBatch.Draw(bg, bgPos, bgColor);
			
			spriteBatch.DrawString(headerFont, header, headerPos, headerColor);
			
			spriteBatch.DrawString(titleFont, title1, title1Pos, headerColor);
			spriteBatch.DrawString(titleFont, title2, title2Pos, headerColor);
			spriteBatch.DrawString(titleFont, title3, title3Pos, headerColor);

			spriteBatch.DrawString(nameFont, name1, name1Pos, Color.Black);
			spriteBatch.DrawString(nameFont, name2, name2Pos, Color.Black);
			spriteBatch.DrawString(nameFont, name3, name3Pos, Color.Black);
			spriteBatch.DrawString(nameFont, name4, name4Pos, Color.Black);
			
			spriteBatch.DrawString(messageFont, message, messagePos, headerColor);
			
			spriteBatch.End();

			base.Draw(gameTime);
		}

	}
}
